﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Massive;
using NUnit.Framework;

namespace Tests
{
    [TestFixture]
    public class MembershipSpecs : TestBase
    {
        public MembershipSpecs()
        {
            this.Describes("User Registration");
            _membership = new Membership();
            _db = new Users();
        }

        [SetUp]
        public void Init()
        {
           Console.WriteLine("");
        }


        [Test]
        public void registration_should_not_accept_email_with_lt_6_chars()
        {
            var result = _membership.Register("p", "password", "password");
            Assert.False(result.Success);
        }


        [Test]
        public void registration_should_not_accept_password_with_lt_6_chars()
        {
            var result = _membership.Register("test@test.com", "x", "x");
            Assert.False(result.Success);
        }

        [Test]
        public void registration_should_not_accept_mismatched_passwords()
        {
            var result = _membership.Register("test@test.com", "password1", "password2");
            Assert.False(result.Success);
        }

        [Test]
        public void email_must_be_unique()
        {
            var result = _membership.Register("test@test.com", "password", "password");
            result = _membership.Register("test@test.com", "password", "password");
            Assert.False(result.Success);
        }


        [Test]
        public void duplicate_email_should_return_message()
        {
            var result = _membership.Register("test@test.com", "password", "password");
            result = _membership.Register("test@test.com", "password", "password");
            Assert.False(result.Message, "This email already exists in our.");
        }
    

        [Test]
        public void user_should_be_saved_on_register()
        {
            var result = _membership.Register("test@test.com", "password", "password");
            Assert.AreEqual(1, _db.All().Count());
        }
    }
}
